package com.popay.purchaseInvoice;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.web.server.WebServer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@EnableFeignClients
@EnableDiscoveryClient
@ComponentScan(basePackages = "com.popay.*")
@EnableDubbo
@SpringBootApplication
public class purchaseInvoiceApplication{

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext application = SpringApplication.run(purchaseInvoiceApplication.class, args);
		Environment env = application.getEnvironment();
		String contextPath = env.getProperty("server.servlet.context-path");
		if (contextPath == null) {
			contextPath = "";
		}
		String agreement = env.getProperty("server.ssl.key-store");
		if (agreement == null) {
			agreement = "http";
		} else {
			agreement = "https";
		}
		log.info("\n---------------------------------------------------------\n" +
						"Application '{}' is running! Access URLs:\n\t" +
						"Local: \t\t{}://localhost:{}{}\n\t" +
						"External: \t{}://{}:{}{}\n\t"+
						"knife4j Api Doc: \t{}://{}:{}{}/doc.html\n"+
						"\n---------------------------------------------------------\n",
				env.getProperty("spring.application.name"),
				agreement,env.getProperty("server.port"),contextPath,
				agreement,InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),contextPath,
				agreement,InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),contextPath);
	}
}
